package com.wang.jmonkey.ca.service.impl;

import com.wang.jmonkey.ca.handler.login.UserServiceHandlerManager;
import org.springframework.boot.web.context.ConfigurableWebServerApplicationContext;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

/**
 * @Description UserDetailsService
 * @Author HeJiawang
 * @Date 2021/5/10 17:40
 */
@Component
public class UserDetailServiceImpl implements UserDetailsService {

    private ConfigurableWebServerApplicationContext context;

    public UserDetailServiceImpl(ConfigurableWebServerApplicationContext context) {
        this.context = context;
    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserServiceHandlerManager manager = context.getBean(UserServiceHandlerManager.class);
        return manager.handler(username);
    }
}
